package com.csj.DesignPattern.prototype.deepClone;

import java.io.*;

//深克隆
public class Test {
    public static void main(String[] args) throws Exception {
        Citation citation = new Citation();
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);

        //通过对象序列化实现深克隆
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("citation.txt"));
        oos.writeObject(citation);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("citation.txt"));
        Citation citation1 = (Citation) ois.readObject();
        ois.close();

        //Citation和Student都需要实现Serializable接口
        citation1.getStudent().setName("李四");

        citation.show();
        citation1.show();

    }
}
